import request, { post } from "@/utils/request";
// /dev-api/system/libraries 新增标注库
export function addlibrary(data) {
  return request({
    url: "/system/libraries",
    method: "post",
    data: data,
  });
}

export function listLibrary(query) {
  return request({
    url: "/system/libraries/list",
    method: "get",
    params: query,
  });
}
export function deleteLibrary(id) {
  return request({
    url: `/system/libraries/${id}`,
    method: "delete",
  });
}
export function getLibrary(id) {
  return request({
    url: `/system/libraries/${id}`,
    method: "get",
  });
}

export function updatelibrary(data) {
  return request({
    url: "/system/libraries",
    method: "put",
    data: data,
  });
}

export function photoAddtoLibrary(data) {
  return request({
    url: "/system/libraries/photo",
    method: "post",
    data: data,
  });
}

export function allPhotoAddtoLibrary(mData) {
  return request({
    url: `/system/libraries/photos/${mData.researchLibrariesId}`,
    method: "get",
    params: mData.params,
  });
}

export function listLibraryPhoto(query) {
  return request({
    url: "/system/libraries/photo/list",
    method: "get",
    params: query,
  });
}
export function getDicts(dictType) {
  return request({
    url: '/system/dict/data/type/' + dictType,
    method: "get",
  });
}
export function deleteLibraryPhotos(libraryId, photoIds) {
  return request({
    url: `/system/libraries/${libraryId}/${photoIds}`,
    method: "delete",
  });
}

export function prevLibraryPhoto(query) {
  return request({
    url: "/system/libraries/photo/upward",
    method: "get",
    params: query,
  });
}
export function nextLibraryPhoto(query) {
  return request({
    url: "/system/libraries/photo/downward",
    method: "get",
    params: query,
  });
}

export function libraryPhotoKindData(query) {
  return request({
    url: "/system/libraries/photo/list/bar",
    method: "get",
    params: query,
  });
}
//该张图片上的标注最后一个标注删除的时候调此接口修改状态为未标注
export function updatePhotoMarkStatus(researchLibrariesId, photoId) {
  return request({
    url: `/system/libraries/photo/update/isMark/${researchLibrariesId}/${photoId}`,
    method: "get",
  });
}

export function uploadPhoto(Mdata, fileId, te) {
  // console.log(Mdata)
  return post(
    "/system/libraries/uploads/" + Mdata.type + "/" + Mdata.compressionRatio,
    Mdata.data,
    {
      headers: { "Content-Type": "multipart/form-data", repeatSubmit: false },
      params: {
        faceLights: Mdata.faceLights,
        faceParts: Mdata.faceParts,
        status: Mdata.status,
        photoUploadTime: Mdata.photoUploadTime,
        uuid: Mdata.uuid,
        researchLibrariesId: Mdata.researchLibrariesId,
        num: Mdata.num,
        fileId,
      },
      timeout: 600000,
      onUploadProgress: (progressEvent) => {
        if (progressEvent.lengthComputable) {
          //是否存在进度
          let complete = Math.floor(
            (progressEvent.loaded / progressEvent.total) * 100
          );
          //complete为上传时的进度 0-100
          let obj = {
            fileId: fileId,
            progress: parseInt(
              (progressEvent.loaded / progressEvent.total) * 100
            ),
            isUploaded: false,
          };
          if (obj.progress >= 96) {
            obj.progress = 96;
          }

          te.$store.dispatch("file/uploadUploadFile", obj);
          // console.log()
          // console.log('进度:onUploadProgress----', obj.progress, progressEvent)
        }
      },
    }
  );
}
